package client;

import java.io.InputStream;
import java.io.OutputStream;

import shared.XMLRMIDocumentTools;
import shared.XMLRMIException;


public class XMLRMIClientRequest {
	
	private InputStream is;
	private OutputStream os;
	private XMLRMICalls call;
	
	public XMLRMIClientRequest(InputStream is, OutputStream os){
		this.is = is;
		this.os=os;
		call = null;
	}
	
	public void setMethodName(String name) throws XMLRMIException{
		this.call = new XMLRMICalls(name);
	}
	
	public void addParameter(Object o) throws XMLRMIException{
		if(call == null)
			throw new XMLRMIException("No method name !");
		call.addParameter(o,null);
	}
	
	public void addParameter(Object o, Class<?> interfaze) throws XMLRMIException{
		if(call == null)
			throw new XMLRMIException("No method name !");
		call.addParameter(o, interfaze);
	}
	
	
	public Object start() throws XMLRMIException{
		if(call == null)
			throw new XMLRMIException("We can't send this request until a name is specify");
		XMLRMIDocumentTools.sendDocument(call.getCallXML(), os);
		
		return call.setResponseXML(XMLRMIDocumentTools.receiveDocument(is));
	}
}
